package cn.tedu.imop.basic.dao.repository.impl;

import cn.tedu.imop.common.context.PageContext;
import cn.tedu.imop.common.pojo.PageData;
import cn.tedu.imop.common.utils.PageInfoToPageDataConverter;
import cn.tedu.imop.basic.dao.mapper.BusinessCategoryMapper;
import cn.tedu.imop.basic.dao.repository.BusinessCategoryRepository;
import cn.tedu.imop.basic.entity.BusinessCategory;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Slf4j
@Repository
public class BusinessCategoryRepositoryImpl implements BusinessCategoryRepository {
    @Autowired
    private BusinessCategoryMapper bussinessCategoryMapper;
    @Override
    public PageData<BusinessCategory> selectBusinessCategoryList(BusinessCategory category) {
        PageContext.startPage();
        List<BusinessCategory> list= bussinessCategoryMapper.selectList(category);
        log.info("Business Category is {}",list);
        return PageInfoToPageDataConverter.convert(new PageInfo<>(list));
    }

    @Override
    public int insertBusinessCategory(BusinessCategory category) {
        category.setCreatedTime(new Date());
        return bussinessCategoryMapper.insert(category);
    }

    @Override
    public BusinessCategory selectBusinessCategoryById(Serializable id) {
        return bussinessCategoryMapper.selectOne(id);
    }

    @Override
    public int updateBusinessCategory(BusinessCategory category) {
        return bussinessCategoryMapper.update(category);
    }
    @Override
    public int deleteBusinessCategoryById(Serializable id) {
        return bussinessCategoryMapper.delete(id);
    }
}
